package com.springcloud.system.user.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springcloud.common.entity.SystemRole;
import com.springcloud.common.entity.SystemUser;
import com.springcloud.system.user.mapper.SystemRoleDao;
import com.springcloud.system.user.mapper.SystemUserDao;
import com.springcloud.system.user.service.SystemUserService;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 系统用户 服务实现类
 * </p>
 *
 * @author mori
 * @since 2019-10-31
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserDao, SystemUser> implements SystemUserService {

    private SystemRoleDao systemRoleDao;

    public SystemUserServiceImpl(SystemRoleDao systemRoleDao) {
        this.systemRoleDao = systemRoleDao;
    }

    @Override
    public Set<SystemRole> getRoleListByUserId(Integer userId) {
        List<SystemRole> roleList = systemRoleDao.getRoleListByUserId(userId);
        return new HashSet<>(roleList);
    }

    @Override
    public SystemUser getSystemUserByUsername(String username) {
        return baseMapper.selectOne(Wrappers.<SystemUser>lambdaQuery().eq(SystemUser::getUserName, username));
    }
}
